package com.budwk.app.waterquality.controllers.admin;

import com.budwk.app.waterquality.config.AppException;
import com.budwk.app.waterquality.services.FileInfoService;
import com.budwk.app.waterquality.services.FormsTemplateConfigService;
import com.budwk.app.waterquality.services.MonthlyReportService;
import com.budwk.app.waterquality.vo.TemplateConfigQueryVo;
import com.budwk.starter.common.openapi.annotation.ApiDefinition;
import com.budwk.starter.common.openapi.annotation.ApiOperation;
import com.budwk.starter.common.page.Pagination;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.log.annotation.SLog;
import lombok.extern.slf4j.Slf4j;
import org.nutz.dao.Cnd;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.*;

import javax.servlet.http.HttpServletResponse;

@IocBean
@At("/waterquality/admin/mnthlyReport")
@ApiDefinition(tag = "月度报表api")
@SLog(tag = "月度报表api")
@Slf4j
public class MonthlyReportController {

    @Inject
    private FormsTemplateConfigService templateConfigService;
    @Inject
    private FileInfoService fileInfoService;
    @Inject
    private MonthlyReportService monthlyReportService;

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "月度报表页面数据")
    public Result<?> listByPage(@Param("..") TemplateConfigQueryVo bean) {
        Pagination p = monthlyReportService.listByPage(bean);
        return Result.data(p);
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "查询所有的模板信息")
    public Result<?> listAll() {
        return Result.data(templateConfigService.query());
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "详情接口")
    public Result<?> getById(@Param("id") String id) {
        return Result.data(monthlyReportService.getById(id));
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "下载数据")
    public Result<?> downData(@Param("id") String id, HttpServletResponse response) {
        try {
            return Result.data(monthlyReportService.downData(id, response));
        } catch (Exception e) {
            log.error("下载报表数据 error: ", e);
            throw new AppException("下载报表数据，请联系管理员！");
        }
    }


}
